class Solution {
public:
    //创建一个哑节点prev，和一个front指针，以及一个back指针
    ListNode* deleteDuplicates(ListNode* head) {
        if(head == nullptr){
            return head;
        }
        ListNode* new_head = new ListNode(0,head);
        ListNode* prev = new_head;
        ListNode* front = head;
        ListNode* back = front->next;
        while(back){ //注意遍历结束条件可以用简单的例子推出遍历链表的结束条件
            if(front->val == back->val){
                while(back && front->val == back->val){
                    front = back;
                    back = back->next;
                }
                prev->next = back;//删除重复的节点
                front = back;
                if(back){
                    back = back->next;
                }
            }
            else{
                prev = front;
                front = back;
                back = back->next;
            }
        }
        ListNode* res = new_head->next;
        delete new_head;
        return res;
    }
};